/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file  Lin.h
 * @brief Semidrive. AUTOSAR 4.3.1 MCAL Lin
 */

#ifndef LIN_H
#define LIN_H

#ifdef __cplusplus
extern "C" {
#endif

/*****************Version Information************/
#define LIN_AR_MAJOR_VERSION  4U
#define LIN_AR_MINOR_VERSION  3U
#define LIN_AR_PATCH_VERSION  1U

#define LIN_SW_MAJOR_VERSION  1U
#define LIN_SW_MINOR_VERSION  0U
#define LIN_SW_PATCH_VERSION  0U

#define LIN_VENDOR_ID         0x8C

#include "Lin_Types.h"
#include "Lin_Ip.h"
#include "Lin_Cfg.h"

#ifndef LIN_CONFIGURATION_VARIANT_PRECOMPILE
#define LIN_CONFIGURATION_VARIANT_PRECOMPILE 1
#endif
#ifndef LIN_CONFIGURATION_VARIANT_LINKTIME
#define LIN_CONFIGURATION_VARIANT_LINKTIME 2
#endif
#ifndef LIN_CONFIGURATION_VARIANT_POSTBUILD_LOADABLE
#define LIN_CONFIGURATION_VARIANT_POSTBUILD_LOADABLE 3
#endif

/* Lin Driver module was not initialized*/
#define LIN_E_UNINIT                      0x00
/* Lin Channel ID is out of Range*/
#define LIN_E_INVALID_CHANNEL             0x02
/* Pointer is out of Range*/
#define LIN_E_INVALID_POINTER             0x03
/* State transition is not valid*/
#define LIN_E_STATE_TRANSITION            0x04
/* Pointer is out of Range*/
#define LIN_E_PARAM_POINTER               0x05
/* Illegal resource access*/
#define LIN_E_ILLEGAL_RES_ACCESS          0x06

/* Service id's for fls functions */
#define LIN_INIT_ID                          0x00
#define LIN_SENDFRAME_ID                     0x01
#define LIN_GOTOSLEEP_ID                     0x02
#define LIN_WAKEUP_ID                        0x03
#define LIN_WAKEUPINTERNAL_ID                0x04
#define LIN_GETSTATUS_ID                     0x05
#define LIN_GOTOSLEEPINTERNAL_ID             0x06
#define LIN_GETVERSIONINFO_ID                0x07
#define LIN_CHECKWAKEUP_ID                   0x08

#define LIN_MODULE_ID                       82U

#define LIN_E_NO_ERROR                     0xFFu

#define LIN_DET_ERROR                  (STD_ON)
#define LIN_DEV_ERROR                   STD_ON
#define LIN_DEV_ERROR_REPORT            STD_ON
#define LIN_GETVERSIONINFO_SERVICE_ID  ((uint8)0x01u)
#define LIN_MAXBYTES_LINFRAME           0x08

#define LIN_MAXNUMBER_FRAMES             12

void Lin_DeInit(void);

void Lin_Init(const Lin_ConfigType *Config );

Std_ReturnType Lin_GoToSleep(uint8 Channel);

Std_ReturnType Lin_GoToSleepInternal(uint8 Channel);

Std_ReturnType Lin_Wakeup(uint8 Channel);

Std_ReturnType Lin_WakeupInternal(uint8 Channel);

Lin_StatusType Lin_GetStatus(uint8 Channel, uint8 **Lin_SduPtr);

Std_ReturnType Lin_CheckWakeup(uint8 Channel);

Std_ReturnType Lin_SendFrame(uint8 Channel, const Lin_PduType *PduInfoPtr);

#if(LIN_VERSION_INFO_API == STD_ON)
void Lin_GetVersionInfo (Std_VersionInfoType * VersionInfo);
#endif

#ifdef __cplusplus
}
#endif
#endif /* LIN_H */
